/*!
    \copyright  Copyright (c) 2023 - 2024 Qualcomm Technologies International, Ltd.\n
                All Rights Reserved.\n
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \ingroup    usb_device
    \brief      USB device framework
*/

#include "usb_device.h"
#include "usb_device_framework.h"
#include "usb_device_utils.h"

#include <usb.h>
#include <usb_hub.h>

#include <local_addr.h>

#include "logging.h"

#include <hydra_macros.h>
#include <panic.h>
#include <stdlib.h>

#include "usb_device_compat.h"

#ifndef INCLUDE_QCOM_USB

#define RESERVED_STRING_INDEX 4
#define MAX_USB_STRING_DESCRIPTORS 255

static uint8 alloc_to_host_eps;
static uint8 alloc_from_host_eps;
static uint8 alloc_string_index;

void usb_device_compat_init(void)
{
    alloc_from_host_eps = 0;
    alloc_to_host_eps = 0;
    alloc_string_index = RESERVED_STRING_INDEX;
}

uint8 UsbAllocEndpointAddr(bool is_to_host)
{
    if (is_to_host)
    {
        if (alloc_to_host_eps == end_point_index_max)
        {
            return 0;
        }
        alloc_to_host_eps++;
        return alloc_to_host_eps | end_point_to_host;
    }
    else
    {
        if (alloc_from_host_eps == end_point_index_max)
        {
            return 0;
        }
        alloc_from_host_eps++;
        return alloc_from_host_eps | end_point_from_host;
    }
}

uint8 UsbAllocStringIndex(void)
{
    if (alloc_string_index == MAX_USB_STRING_DESCRIPTORS)
    {
        return 0;
    }

    alloc_string_index += 1;

    return alloc_string_index;
}


bool UsbInterfaceExternal(uint16 interface, uint16 owner)
{
    UNUSED(interface);
    UNUSED(owner);

    return TRUE;
}

#endif /* INCLUDE_QCOM_USB */
